package com.yksj.healthtalk.ui.home;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.RingPlayer;
import com.yksj.healthtalk.ui.doctor.DoctorExactSearchActivity;
/**
 * 我的壹健康  我的医生
 * @author jack_tang
 *
 */
public class MyDoctorListActivity extends BaseFragmentActivity implements
		OnClickListener {
	MyDoctorListFrament fragment;
	WithdrawingRegistrationFragment fragment2;
	List<Fragment> fragments;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		setContentView(R.layout.pull_main_friend_group);
		setUpView();
		// setData();
		fragments = new ArrayList<Fragment>();
		fragment = new MyDoctorListFrament();
		FragmentManager manager = getSupportFragmentManager();
		FragmentTransaction transaction = manager.beginTransaction();
		transaction.add(R.id.frameLayout, fragment);
		fragments.add(fragment);
		transaction.commitAllowingStateLoss();
	}

	private void setUpView() {
		initTitle();
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setText("搜索");
		titleLeftBtn.setOnClickListener(this);
		titleRightBtn2.setOnClickListener(this);
		titleTextV.setText(getString(R.string.my_doctor));
		
		findViewById(R.id.top_line).setVisibility(View.GONE);
		
	}
	

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.title_right2:
			Intent intent = new Intent(getApplicationContext(), DoctorExactSearchActivity.class);
			startActivity(intent);
			break;
		case R.id.title_ok:
			RingPlayer.playPressSound(this);
			break;

		}
	}


	@Override
	public void onBackPressed() {
		if (fragment2 != null
				&& !fragment2.isDetached()) {
			FragmentTransaction transaction = getSupportFragmentManager()
					.beginTransaction();
			if (fragment2 != null) {
				transaction.detach(fragment2);
			}
			if (fragment != null) {
				transaction.attach(fragment).addToBackStack(null);
			}
			fragments.remove(0);
			fragments.add(fragment);
			transaction.setCustomAnimations(R.anim.slide_in_left,
					R.anim.slide_out_right);
			transaction.commitAllowingStateLoss();
			titleTextV.setText(R.string.my_doctor);
		} else {
			finish();
		}
	}


}